package com.zs.admin.controller.wisdbook;

import com.zs.admin.aop.Log;
import com.zs.admin.service.wisdbook.IWisdbookDirService;
import com.zs.admin.validate.wisdbook.WisdbookDirCreateValidate;
import com.zs.admin.validate.wisdbook.WisdbookDirSearchValidate;
import com.zs.admin.validate.wisdbook.WisdbookDirUpdateValidate;
import com.zs.admin.validate.commons.IdValidate;
import com.zs.admin.vo.wisdbook.WisdbookDirDetailVo;
import com.zs.admin.vo.wisdbook.WisdbookDirListedVo;
import com.zs.common.core.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/wisdbook/dir")
@Api(tags = "智书目录管理")
public class WisdbookDirController {

    @Resource
    IWisdbookDirService iWisdbookDirService;

    @PostMapping("/list")
    @ApiOperation(value="智书目录列表")
    public AjaxResult<List<WisdbookDirListedVo>> list(@Validated @RequestBody WisdbookDirSearchValidate searchValidate) {
        List<WisdbookDirListedVo> list = iWisdbookDirService.list(searchValidate);
        return AjaxResult.success(list);
    }

    @PostMapping("/detail")
    @ApiOperation(value="智书目录详情")
    public AjaxResult<WisdbookDirDetailVo> detail(@Validated @RequestBody IdValidate idValidate) {
        WisdbookDirDetailVo detail = iWisdbookDirService.detail(idValidate);
        return AjaxResult.success(detail);
    }

    @Log(title = "智书目录新增")
    @PostMapping("/add")
    @ApiOperation(value="智书目录新增")
    public AjaxResult<WisdbookDirDetailVo> add(@Validated @RequestBody WisdbookDirCreateValidate createValidate) {
        WisdbookDirDetailVo dir = iWisdbookDirService.add(createValidate);
        return AjaxResult.success(dir);
    }

    @Log(title = "智书目录编辑")
    @PostMapping("/edit")
    @ApiOperation(value="智书目录编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody List<WisdbookDirUpdateValidate> updateValidateList) {
        iWisdbookDirService.edit(updateValidateList);
        return AjaxResult.success();
    }

    @Log(title = "智书目录删除")
    @PostMapping("/del")
    @ApiOperation(value="智书目录删除")
    public AjaxResult<Object> del(@Validated @RequestBody List<IdValidate> idValidateList) {
        iWisdbookDirService.del(idValidateList);
        return AjaxResult.success();
    }

}
